Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(anta): add test atomic results #937

Open
wants to merge 55 commits into
base: main
Choose a base branch
from

Conversation

mtache
Copy link
Collaborator

@mtache mtache commented Nov 26, 2024

Description

Add anta.result_manager.models.AtomicTestResult model.
Create a atomic_results field in anta.result_manager.models.TestResult model.

Reports supported are table, text, json and jinja. csv and markdown will be supported in another PR.

Considering the test:

anta.tests.connectivity:
- VerifyReachability:
    filters:
      tags:
      - mtache-leaf2a
    hosts:
    - description: mtache-spine1 Ethernet3/1
      destination: 10.255.255.4
      repeat: 1
      source: Ethernet49/1
      vrf: default
    - destination: 10.255.255.10
      repeat: 1
      source: 10.255.255.11
      vrf: default

The exemple below is a serialisation of the TestResult model of the test defined above:

  {
    "name": "mtache-leaf2a",
    "test": "VerifyReachability",
    "categories": [
      "connectivity"
    ],
    "description": "Test network reachability to one or many destination IP(s).",
    "inputs": {
      "filters": {
        "tags": [
          "mtache-leaf2a"
        ]
      },
      "hosts": [
        {
          "description": "mtache-spine1 Ethernet3/1",
          "destination": "10.255.255.4",
          "source": "Ethernet49/1",
          "vrf": "default",
          "repeat": 1,
          "size": 100,
          "df_bit": false
        },
        {
          "destination": "10.255.255.10",
          "source": "10.255.255.11",
          "vrf": "default",
          "repeat": 1,
          "size": 100,
          "df_bit": false
        }
      ]
    },
    "result": "failure",
    "messages": [
      "Unreachable Destination 10.255.255.4 (mtache-spine1 Ethernet3/1) from Ethernet49/1 in VRF default"
    ],
    "atomic_results": [
      {
        "description": "Destination 10.255.255.4 (mtache-spine1 Ethernet3/1) from Ethernet49/1 in VRF default",
        "inputs": {
          "description": "mtache-spine1 Ethernet3/1",
          "destination": "10.255.255.4",
          "source": "Ethernet49/1",
          "vrf": "default",
          "repeat": 1,
          "size": 100,
          "df_bit": false
        },
        "result": "failure",
        "messages": [
          "Unreachable Destination 10.255.255.4 (mtache-spine1 Ethernet3/1) from Ethernet49/1 in VRF default"
        ]
      },
      {
        "description": "Destination 10.255.255.10 from 10.255.255.11 in VRF default",
        "inputs": {
          "destination": "10.255.255.10",
          "source": "10.255.255.11",
          "vrf": "default",
          "repeat": 1,
          "size": 100,
          "df_bit": false
        },
        "result": "success",
        "messages": []
      }
    ]
  }

Fixes #427

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)
  • Make the reports display atomic results

@mtache mtache changed the title feat(anta): add anta.result_manager.models.AtomicTestResult feat(anta): add test atomic results Nov 26, 2024
@mtache mtache marked this pull request as ready for review November 26, 2024 15:36
Copy link

codspeed-hq bot commented Nov 26, 2024

CodSpeed Performance Report

Merging #937 will degrade performances by 23.36%

Comparing mtache:issue-427 (76a9a86) with main (1f033f4)

Summary

⚡ 4 improvements
❌ 4 regressions
✅ 14 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main mtache:issue-427 Change
test_anta_dry_run[1-device] 52.5 ms 64.4 ms -18.48%
test_anta_dry_run[2-devices] 91.6 ms 115.4 ms -20.65%
test_jinja[1-device] 49.1 ms 43.3 ms +13.39%
test_jinja[2-devices] 93.1 ms 81.1 ms +14.8%
test_json[1-device] 32.2 ms 19.7 ms +63.11%
test_json[2-devices] 63.3 ms 38.6 ms +64%
test_get_coroutines[1-device] 38.7 ms 50.4 ms -23.13%
test_get_coroutines[2-devices] 76.3 ms 99.6 ms -23.36%

anta/cli/nrfu/__init__.py Outdated Show resolved Hide resolved
anta/cli/nrfu/utils.py Outdated Show resolved Hide resolved
anta/result_manager/__init__.py Show resolved Hide resolved
anta/result_manager/models.py Outdated Show resolved Hide resolved
anta/reporter/__init__.py Outdated Show resolved Hide resolved
@gmuloc gmuloc modified the milestones: v1.2.0, v1.3.0 Dec 24, 2024
add_result(result)
return table

def report(self, manager: ResultManager) -> Table:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make this non breaking we need to keep report_all function with the possibility to change the title

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is internal to ANTA. The title argument should have never been there anyway since it's always the default value... It is never used.

anta/result_manager/__init__.py Outdated Show resolved Hide resolved
anta/models.py Show resolved Hide resolved
console.print("Tags found:")
console.print_json(json.dumps(sorted(tags), indent=2))
t.update(device.tags)
console.print("Tags defined in inventory:")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update the documentation

anta/cli/nrfu/utils.py Show resolved Hide resolved
pytest.param(None, 5, 5, id="all results"),
pytest.param(None, 0, 0, id="result for host1 when no host1 test"),
pytest.param(None, 5, 5, id="result for test VerifyTest3"),
pytest.param("Custom title", 5, 5, id="Change table title"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will probably need to add this back to be non breaking

tests/units/result_manager/conftest.py Show resolved Hide resolved
tests/units/result_manager/conftest.py Outdated Show resolved Hide resolved
anta/models.py Show resolved Hide resolved
anta/models.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Add granular results for tests with lists of inputs
3 participants